package com.atues.thread.state;

public class TestState extends Thread
{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(" i=" + i);
        }
    }

    public static void main(String[] args) {
       Thread thread = new Thread(()->{
           for (int i = 0; i < 5; i++) {
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
           System.out.println("////////");
       });
        State state = thread.getState();
        System.out.println("线程状态：" + state); // NEW
        thread.start();
        state = thread.getState();
        System.out.println("线程状态：" + state); // RUNNABLE
        while (state != Thread.State.TERMINATED) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            state = thread.getState();
            System.out.println("线程状态：" + state); // TIMED_WAITING
        }
    }
}
